<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: add.class.php 97087 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
  defined('PHPFOX') or exit('NO DICE!');
  class Follow_Component_Controller_Add extends Phpfox_Component
  {
      public function process()
      {
          
          phpfox::isUser(true);
          $iId = $this->request()->get('id', false);
          $sType = $this->request()->get('type', false);
          $iItemId = $this->request()->get('oid', false);
          if($sType == 'user')
            {
                $sLink = 'follow';
            }
            elseif($sType == 'pages')
            {
                $sLink = 'pages.'.$iItemId.'.follow.follower';
            }
          if(!empty($iId) && !empty($sType) && !empty($iItemId))
          {
              $bCheckInt = (int)$iItemId;
              if(md5($bCheckInt) == md5($iItemId))
              {
                    if(phpfox::getUserId() == $iId && $sType == 'user')
                    {
                        $sMessage =  Phpfox::getPhrase('follow.you_can_not_follow_yourself');        
                    }
                    if(phpfox::getService('follow')->canFollow($iItemId, $sType))
                    {
                        if(!Phpfox::getService('follow')->isFollow($iId, $iItemId, $sType))
                        {
                            if(phpfox::getService('follow')->follow($iItemId, $sType))
                            {
                                $sMessage =  Phpfox::getPhrase('follow.follow_successfully');        
                            }
                            else
                            {
                                $sMessage =  Phpfox::getPhrase('follow.user_id_not_exists');
                            } 
                        }
                        else
                        {
                            $sMessage =  phpfox::getPhrase('follow.you_already_followed_this_user');
                        }
                    }
                    else
                    {
                        $sMessage =  Phpfox::getPhrase('follow.you_can_not_follow_this_user');    
                    }
              }
              else
              {
                  $sMessage =  Phpfox::getPhrase('follow.user_id_must_be_an_integer_number');   
              }
          }
          else
          {
              $sMessage =  Phpfox::getPhrase('follow.following_user_id_not_found');
          }
          $this->url()->send($sLink, null,$sMessage);
      }
  }
?>
